Skip to content

Conversation

timg236
Copy link
Contributor

@timg236 timg236 commented Aug 12, 2025

Client side library and application for the Raspberry Pi firmware cryptography service. The firmware mailbox based crypto service provides limited support for cryptographic operations using a ECDSA p256 private core stored in OTP (using rpi-otp-private-key).

The current operations are

  • Get number of OTP keys
  • Get status for key
  • Set status for a key (runtime lock)
  • ECDSA SHA256 signature
  • HMAC SHA256 (max message size 2KB)

rpifwcrypto is a command line application designed to allow the
crypto operations to be easily used in shell scripts.

rpifwcrypto.h provides a library interface so that this can be
embedded in other applications.

Direct usage of mailbox API (vcmailbox) is not recommended
because this is a new feature and the mailbox API is not frozen.

@timg236
Copy link
Contributor Author

timg236 commented Aug 12, 2025

@roliver-rpi Adding early draft PR here so that we can start integrating this in parallel with firmware dependencies.

@timg236 timg236 marked this pull request as ready for review August 14, 2025 10:08
@timg236
Copy link
Contributor Author

timg236 commented Aug 14, 2025

Firmware changes are now merged (but not released)

# Find GnuTLS package
find_package(GnuTLS REQUIRED)

add_compile_definitions(LIBRARY_BUILD=1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is a hangover from the original - pinctrl or piolib, I imagine - and appears not to be used here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you referring to LIBRARY_BUILD=1 ? librpifwcrypto.so should eventually be part of the APT package

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - LIBRARY_BUILD is a flag I created for pinctrl (and later piolib) to replace the linker magic for collecting constructors with an explicit function that calls them all; it has no effect otherwise.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line still seems to be present in the latest version. And this file is also missing a newline (aren't you a vim user)?

install(TARGETS rpi-fw-crypto RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS rpifwcrypto
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a newline.

mbox_close(mb);

return (rc < 0) ? rc : RPI_FW_CRYPTO_SUCCESS;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline.

}
#endif

#endif /* RPI_FW_CRYPTO_H */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -74,7 +74,6 @@ static void mbox_close(int file_desc) {
close(file_desc);
}


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional? If so, there's another double-blank on lines 57-58.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted the remnants of some leftover changes to vcmailbox.c

return rc;

if (msg.resp.length > sig_max_len)
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This brace usage doesn't match the rest of this code, but there are other examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@timg236 timg236 force-pushed the rpifwcrypto branch 2 times, most recently from 1223cb5 to f77e855 Compare August 18, 2025 11:08
# Find GnuTLS package
find_package(GnuTLS REQUIRED)

option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're changing the default build for rpifwcrypto to shared libraries then you'll need to update the top-level README. And perhaps provide rpifwcrypto/README.md as well.

Client side library and application for the Raspberry Pi firmware
cryptography service. The firmware mailbox based crypto service
provides limited support for cryptographic operations using
a ECDSA P-256 stored in OTP (using rpi-otp-private-key).

The current operations are
* Get number of OTP keys
* Get status for key
* Set status for a key (runtime lock)
* ECDSA SHA256 signature
* HMAC SHA256 (max message size 2KB)
  e.g. LUKS passphrase = HMAC(device-unique-ley, serial64 + EMMC CID)

 rpifwcrypto is a command line application designed to allow the
 crypto operations to be easily used in shell scripts.

 rpifwcrypto.h provides a library interface so that this can be
 embedded in other applications.

 Direct usage of mailbox API (vcmailbox) is not recommended
 because this is a new feature and the mailbox API is not frozen.
@pelwell pelwell merged commit d564d80 into raspberrypi:master Aug 18, 2025
@timg236 timg236 deleted the rpifwcrypto branch August 20, 2025 15:52
popcornmix added a commit to raspberrypi/firmware that referenced this pull request Aug 20, 2025
See: raspberrypi/utils#139

firmwware: bootcode: Add boot.img ramdisk support for Pi3 and earlier devices
popcornmix added a commit to raspberrypi/rpi-firmware that referenced this pull request Aug 20, 2025
See: raspberrypi/utils#139

firmwware: bootcode: Add boot.img ramdisk support for Pi3 and earlier devices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants